package com.yumeng.framework.auth.security.session;

import com.yumeng.common.api.ApiCode;
import com.yumeng.common.utils.ResponseUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

import java.io.IOException;

/**
 * 过期会话（被挤下线）
 *
 * @author wxd
 * @date 2024/10/25 10:24
 */
@Slf4j
public class JsonSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        log.info("onExpiredSessionDetected 在线踢人");
        HttpServletResponse response = event.getResponse();
        ResponseUtils.writeJson(response, ApiCode.AUTH_EXPIRED, "会话过期");
    }

}
